package org.x.usermod.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.x.commonmod.enums.LogAsync;
import org.x.usermod.dto.AchieveSmsDTO;
import org.x.commonmod.config.Result;
import org.x.usermod.dto.pubRegisterDTO;
import org.x.usermod.dto.LawyerRegisterDTO;
import org.x.usermod.entity.SysUser;
import org.x.usermod.service.RegisterService;
import org.x.usermod.vo.lawyerRegisterVO;
import org.x.usermod.vo.pubRegisterVO;

@RestController
@RequestMapping("/api")
public class RegisterController {
    @Autowired
    private RegisterService registerService;

    /**
     * 获取短信验证码（纯数字）
     * @param achieveSmsDTO
     * @return
     */
    @PostMapping("/sms/send")
    @LogAsync("获取短信验证码")
    public Result achieveSms(@RequestBody AchieveSmsDTO achieveSmsDTO) {
        String code = registerService.achieveSms(achieveSmsDTO);
        return Result.ok("短信验证码发送成功",code);
    }

    /**
     * 公众注册接口
     * @param pubRegisterDTO
     * @return
     */
    @PostMapping("/pub/register")
    @LogAsync("公众注册")
    public Result pubRegister(@RequestBody pubRegisterDTO pubRegisterDTO) {
        pubRegisterVO pubRegisterVO = registerService.pubRegister(pubRegisterDTO);
        return Result.ok(pubRegisterVO);
    }
    /**
     * 律师注册接口
     * @param lawyerRegisterDTO
     * @return
     */
    @PostMapping("/lawyer/register")
    @LogAsync("律师注册")
    public Result lawyerRegister(@RequestBody LawyerRegisterDTO lawyerRegisterDTO) {
        lawyerRegisterVO lawyerRegisterVO = registerService.lawyerRegister(lawyerRegisterDTO);
        return Result.ok("提交成功，请耐心等待等待审核",lawyerRegisterVO);
    }

    /**
     * 管理员注册接口
     * @param sysUser
     * @return
     */
    @PostMapping("/admin/create")
    public Result adminRegister(@RequestBody SysUser sysUser) {
        String token=registerService.adminRegister(sysUser);
        return Result.ok("管理员添加成功",token);
    }
}
